﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class KetQuaTimKiem : System.Web.UI.Page
{
    int tpid, ltid, ldoid ,intg;
    string strg, strtk;
    string tinhthanh;
    string loaitinrao;
    string loaidiaoc;

    protected void Page_Load(object sender, EventArgs e)
    {
        //tinhthanh = Session["tinhthanh"].ToString();
        //loaitinrao = Session["loaitinrao"].ToString();
        //loaidiaoc = Session["loaidiaoc"].ToString();
        TinDiaOcBan();        
    }
    public void TinDiaOcBan()
    {
        String sql;
        tpid = Convert.ToInt32(this.Request["tpid"]);
        ltid = Convert.ToInt32(this.Request["ltid"]);
        ldoid = Convert.ToInt32(this.Request["ldoid"]);
        strtk = this.Request["strtk"];
        strg = this.Request["strg"];
        intg = Convert.ToInt32(strg);
        //tpid = Convert.ToInt32(this.tinhthanh);
        //ltid = Convert.ToInt32(this.loaitinrao);
        //ldoid = Convert.ToInt32(this.loaidiaoc);
        ConnectionData sqlconn = new ConnectionData();        
        sql = "select dt.Id, dt.tieu_de, dt.Ngay_Bat_Dau, dc.So_Nha, dc.Duong_Pho, p.Phuong_Xa, q.Quan_Huyen, tp.Ten_TP,dt.Thuong_Luong, do.Hinh_Anh, do.So_Lau, do.So_Phong_ngu, do.so_phong_khach, do.so_phong_tam, do.so_phong_tam, do.so_phong_khac, do.DTKV, do.DTSD, do.So_Lan_Xem, 0 ";
        sql += "from DANG_TIN as dt, DIA_OC as do, DIA_CHI as dc, QUAN_HUYEN as q, PHUONG_XA as p, THANH_PHO as tp ";
        sql += "where dt.Dia_Oc_ID = do.Id and dc.TP_Id = tp.Id and q.TP_Id = tp.Id and p.Quan_id = q.Id and dc.Quan_Id = q.Id ";
        sql += "and dc.Phuong_id = p.Id and do.Dia_Chi_ID = dc.Id ";
        sql += "and dt.Loai_Tin_ID = " + ltid;
        sql += " and tp.Id = " + tpid;
        sql += " and do.Loai_Dia_Oc_id = " + ldoid;
        sql += " and (dt.tieu_de like'%" + strtk + "%' or dc.Duong_Pho like'%" + strtk + "%' or p.Phuong_Xa like'%" + strtk + "%' or q.Quan_Huyen like'%" + strtk + "%' or tp.Ten_TP like '%" + strtk + "%' or do.Gia like '%"+ intg +"%' ) ";
        sql += " order by dt.id desc";

        DataSet ds = new DataSet();
        ds = sqlconn.ExecuteQuery(sql);
        dtltindiaocban.DataSource = ds;
        dtltindiaocban.DataBind();
    }

    protected void dtlTintucDiaoc_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        //tin moi nhat
        Image img = default(Image);
        img = (Image)e.Item.FindControl("imgHinh");
        img.ImageUrl = "~/HinhDiaOc/" + Convert.ToString(((DataRowView)e.Item.DataItem)["Hinh_Anh"]);

        //vi tri

        Label vitri = default(Label);
        vitri = (Label)e.Item.FindControl("lblVitri");
        String SoNha = Convert.ToString(((DataRowView)e.Item.DataItem)["so_nha"]);
        String Duong = Convert.ToString(((DataRowView)e.Item.DataItem)["duong_pho"]);
        String Phuong = Convert.ToString(((DataRowView)e.Item.DataItem)["phuong_xa"]);
        String Quan = Convert.ToString(((DataRowView)e.Item.DataItem)["quan_huyen"]);
        String TP = Convert.ToString(((DataRowView)e.Item.DataItem)["ten_tp"]);
        //vitri.Text = SoNha + " - " + Duong + " - " + Phuong + " - " + Quan + " - " + TP;

        //tieu de tin dang
        HyperLink tieude = default(HyperLink);
        tieude = (HyperLink)e.Item.FindControl("hpltieude");
        tieude.Text = Convert.ToString(((DataRowView)e.Item.DataItem)["Tieu_de"]);
        tieude.NavigateUrl = "~/Chitietdiaoc.aspx?id=" + Convert.ToString(((DataRowView)e.Item.DataItem)["Id"]);

        //ngay dang
        Label ngaydang = default(Label);
        ngaydang = (Label)e.Item.FindControl("lblNgayDang");
        //ngaydang.Text = Convert.ToString(((DataRowView)e.Item.DataItem)["ngay_bat_dau"]);

        //DTKV
        Label DTKV = default(Label);
        DTKV = (Label)e.Item.FindControl("lblDTKV");
        DTKV.Text = Convert.ToString(((DataRowView)e.Item.DataItem)["DTKV"]);

        //DTSD
        Label DTSD = default(Label);
        DTSD = (Label)e.Item.FindControl("lblDTSD");
        //DTSD.Text = Convert.ToString(((DataRowView)e.Item.DataItem)["DTSD"]);

        //Cau Truc
        Label CauTruc = default(Label);
        CauTruc = (Label)e.Item.FindControl("lblCauTruc");
        String Lau = Convert.ToString(((DataRowView)e.Item.DataItem)["so_lau"]);
        String PhongKhach = Convert.ToString(((DataRowView)e.Item.DataItem)["so_phong_khach"]);
        String PhongNgu = Convert.ToString(((DataRowView)e.Item.DataItem)["so_phong_ngu"]);
        String PhongTam = Convert.ToString(((DataRowView)e.Item.DataItem)["so_phong_tam"]);
        String PhongKhac = Convert.ToString(((DataRowView)e.Item.DataItem)["so_phong_khac"]);
        if (Lau != "")
            CauTruc.Text = Lau + " lầu - ";
        if (PhongKhach != "")
            CauTruc.Text = CauTruc.Text + PhongKhach + " phòng khách - ";
        if (PhongNgu != "")
            CauTruc.Text = CauTruc.Text + PhongNgu + " phòng ngủ - ";
        if (PhongTam != "")
            CauTruc.Text = CauTruc.Text + PhongTam + " phòng tắm/vệ sinh - ";
        if (PhongKhac != "")
            CauTruc.Text = CauTruc.Text + PhongKhac + " phòng khác";

        //Gia
        Label Gia = default(Label);
        Gia = (Label)e.Item.FindControl("lblGia");
        Gia.Text = Convert.ToString(((DataRowView)e.Item.DataItem)["Gia"]);

        //Thuong luong
        Label ThuongLuong = default(Label);
        ThuongLuong = (Label)e.Item.FindControl("lblThuongLuong");
        //ThuongLuong.Text = Convert.ToString(((DataRowView)e.Item.DataItem)["Thuong_Luong"]);

        //So lan xem
        Label LuotXem = default(Label);
        LuotXem = (Label)e.Item.FindControl("lblLanXem");
        //LuotXem.Text = Convert.ToString(((DataRowView)e.Item.DataItem)["So_Lan_Xem"]);

        //ket thuc tin moi nhat

    }

    protected void dtltindiaocban_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        dtlTintucDiaoc_ItemDataBound(sender, e);
    }
}